class: center, middle, inverse, title-slide # Choropleth for continuous variables --- layout: true <div class="dk-footer"> <span> <a href="https://rfortherestofus.com/" target="_blank">R for the Rest of Us </a> </span> </div> --- class: center, middle, dk-section-title background-image:url("https://images.pexels.com/photos/7135077/pexels-photo-7135077.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260") background-size: cover # Choropleth of continuous variables --- # Continuous variable choropleth .pull-left[ <center> <img src='images/gg_london_school_leavers_colorbar.png' width='700px'/> </center> ] -- .pull-right[ <center> <img src='images/gg_london_school_leavers_binned.png' width='700px'/> </center> ] --- ## NA values and continuous choropleth .pull-left[ To label NA values in continuous choropleth we need to go through 3 steps: - Find an unused aesthetic in the chart (the NA aesthetic) - Override the guide for the NA aesthetic - Set the `na.value` in the fill scale ] .pull-right[ <center> <img src='images/gg_london_school_leavers.png' width='100%'/> </center> ] --- ### Find an unused <span style='color:#c03728'>aesthetics
</span> in the chart The <span style='color:#f5c04a'>continuous fill guides</span> **do not have space** for an NA label. -- We need to create a new <span style='color:#f5c04a'>guide</span> - which means we need to choose an <span style='color:#c03728'>NA aesthetic</span> Good choices include: - shape - alpha --- ### Override the <span style='color:#f5c04a'>guide
</span> for the NA aesthetic Now that we've created an aesthetic and corresponding guide, we need to override the aesthetics: ```r gg_chart + guides(shape = guide_legend(override.aes = list(fill = "pink"))) ``` --- ### Set the `na.value` in the fill scale While the continuous fill guides don't have space for a *label* they do allow us to set an `NA` *color*: ```r gg_chart + scale_fill_viridis_c(na.value = "pink") ``` --- class: inverse # Your turn .pull-left[ Use the `your-turn.R` script in `02_07` to build this map. You'll need to add a guide item for District of California which has an NA value. - Create an NA aesthetic - Override the guide aesthetics - Set the `na.value` for the fill aesthetic ] .pull-right[ <!-- --> ]